import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '~/Layout.vue'
import bar from '@/plugins/loadingbar'


const users = () => import('~/user/UserList.vue')
const orders = () => import('~/work/OrderList.vue')
const login = () => import('~/Login.vue')
const error = () => import('~/404.vue')

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: '数据驾驶舱',
    meta: { title: '首页' },
    component: Home,
    children: [
      {
        path: 'users',
        name: '员工列表',
        meta: {
          title: '员工列表',
          module: '员工管理'
        },
        component: users
      },
      {
        path: 'orders',
        name: '工单列表',
        meta: {
          title: '工单列表',
          module: '业务管理'
        },
        component: orders
      },
    ]
  },
  {
    path: '/login',
    name: '登录',
    meta: {
      title: '登录',
    },
    component: login
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'Error 404',
    component: error
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})



router.beforeEach((to, from, next) => {
  document.title = '海尔 海门仁杰店 - ' + to.meta.title
  console.log('bar start');
  
  bar.start()

  setTimeout(next, 1000)
})



router.afterEach(bar.end)

export default router
